package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbDictionary;
import com.ruoyi.system.service.ITbDictionaryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 数据字典Controller
 * 
 * @author lzd
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/dataDictionary")
public class TbDictionaryController extends BaseController
{
    @Autowired
    private ITbDictionaryService tbDictionaryService;

    /**
     * 查询数据字典列表
     */
//    @RequiresPermissions("system:dataDictionary:list")
    @GetMapping("/list")
    public TableDataInfo list(TbDictionary tbDictionary)
    {
        startPage();
        List<TbDictionary> list = tbDictionaryService.selectTbDictionaryList(tbDictionary);
        return getDataTable(list);
    }

    /**
     * 导出数据字典列表
     */
    @RequiresPermissions("system:dataDictionary:export")
    @Log(title = "数据字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDictionary tbDictionary)
    {
        List<TbDictionary> list = tbDictionaryService.selectTbDictionaryList(tbDictionary);
        ExcelUtil<TbDictionary> util = new ExcelUtil<TbDictionary>(TbDictionary.class);
        util.exportExcel(response, list, "数据字典数据");
    }

    /**
     * 获取数据字典详细信息
     */
    @RequiresPermissions("system:dataDictionary:query")
    @GetMapping(value = "/{dictionaryId}")
    public AjaxResult getInfo(@PathVariable("dictionaryId") Long dictionaryId)
    {
        return success(tbDictionaryService.selectTbDictionaryByDictionaryId(dictionaryId));
    }

    /**
     * 新增数据字典
     */
    @RequiresPermissions("system:dataDictionary:add")
    @Log(title = "数据字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDictionary tbDictionary)
    {
        return toAjax(tbDictionaryService.insertTbDictionary(tbDictionary));
    }

    /**
     * 修改数据字典
     */
    @RequiresPermissions("system:dataDictionary:edit")
    @Log(title = "数据字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDictionary tbDictionary)
    {
        return toAjax(tbDictionaryService.updateTbDictionary(tbDictionary));
    }

    /**
     * 删除数据字典
     */
    @RequiresPermissions("system:dataDictionary:remove")
    @Log(title = "数据字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dictionaryIds}")
    public AjaxResult remove(@PathVariable Long[] dictionaryIds)
    {
        return toAjax(tbDictionaryService.deleteTbDictionaryByDictionaryIds(dictionaryIds));
    }
}
